﻿<ViewDataFormTemplateSpec
	xmlns="bb_appfx_viewdataformtemplate"
	xmlns:common="bb_appfx_commontypes"
	ID="336f585c-1574-4569-8eb5-a6ccaaf0b735"
	Name="Constituent GUID View Form"
	Description="Get the GUID of a constituent record from the lookup ID or any alternate ID"
	Author="Blackbaud Professional Services"
	DataFormInstanceID="3b4d6f25-0ef6-4e0a-97f9-e42aef5cad0c"
	RecordType="Constituent"
  common:SecurityUIFolder="Service Bus Adapter"
	>

  <!-- define the SP that returns the data used by the form -->
  <SPDataForm SPName="USR_USP_DATAFORMTEMPLATE_VIEW_CONSTITUENT_GET_GUID">
    <common:CreateProcedureSQL>
      <![CDATA[
create procedure dbo.USR_USP_DATAFORMTEMPLATE_VIEW_CONSTITUENT_GET_GUID
(
	@ID nvarchar(255),
	@DATALOADED bit = 0 output,
	@CONSTITUENTID uniqueidentifier = null output
)
as
	set nocount on;
	
	-- be sure to set this, in case the select returns no rows
	set @DATALOADED = 0;
	
	-- populate the output parameters, which correspond to fields on the form.  Note that
	-- we set @DATALOADED = 1 to indicate that the load was successful.  Otherwise, the system
	-- will display a "no data loaded" message.
	select 
    @DATALOADED = 1,
		@CONSTITUENTID = c.ID
	from 
    dbo.CONSTITUENT c
	where 
    c.LOOKUPID = @ID 
	
  if @DATALOADED = 0
    begin
      select
        @DATALOADED = 1,
        @CONSTITUENTID = ali.CONSTITUENTID
      from
        dbo.ALTERNATELOOKUPID ali
      where
        ali.ALTERNATELOOKUPID = @ID
    end
    
	return 0;
			]]>
    </common:CreateProcedureSQL>
  </SPDataForm>

  <!-- describe fields on the form, which correspond to parameters on the SP.  Note that system paramters 
	like the context @ID, @DATALOADED, and @CURRENTAPPUSERID need not be listed. -->
  <common:FormMetaData FixedDialog="true">
    <common:FormFields>
      <common:FormField FieldID="CONSTITUENTID" Caption="Constituent ID" DataType="Guid" />
    </common:FormFields>
  </common:FormMetaData>

</ViewDataFormTemplateSpec>